package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BasisCode;
import com.ruoyi.system.service.IBasisCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 签到二维码Controller
 *
 * @author ruoyi
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/system/code")
public class BasisCodeController extends BaseController
{
    @Autowired
    private IBasisCodeService basisCodeService;

    /**
     * 查询签到二维码列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasisCode basisCode)
    {
        startPage();
        List<BasisCode> list = basisCodeService.selectBasisCodeList(basisCode);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:code:code')")
    @GetMapping("/code")
    public TableDataInfo code(BasisCode basisCode)
    {
        startPage();
        List<BasisCode> list = basisCodeService.selectBasisCodeList(basisCode);
        return getDataTable(list);
    }
    /**
     * 导出签到二维码列表
     */
    @PreAuthorize("@ss.hasPermi('system:code:export')")
    @Log(title = "签到二维码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasisCode basisCode)
    {
        List<BasisCode> list = basisCodeService.selectBasisCodeList(basisCode);
        ExcelUtil<BasisCode> util = new ExcelUtil<BasisCode>(BasisCode.class);
        return util.exportExcel(list, "签到二维码数据");
    }

    /**
     * 获取签到二维码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:code:query')")
    @GetMapping(value = "/{codeId}")
    public AjaxResult getInfo(@PathVariable("codeId") Long codeId)
    {
        return AjaxResult.success(basisCodeService.selectBasisCodeById(codeId));
    }

    /**
     * 新增签到二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:add')")
    @Log(title = "签到二维码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasisCode basisCode)
    {
        return toAjax(basisCodeService.insertBasisCode(basisCode));
    }

    /**
     * 修改签到二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:edit')")
    @Log(title = "签到二维码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasisCode basisCode)
    {
        return toAjax(basisCodeService.updateBasisCode(basisCode));
    }

    /**
     * 删除签到二维码
     */
    @PreAuthorize("@ss.hasPermi('system:code:remove')")
    @Log(title = "签到二维码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codeIds}")
    public AjaxResult remove(@PathVariable Long[] codeIds)
    {
        return toAjax(basisCodeService.deleteBasisCodeByIds(codeIds));
    }
}
